package com.sgx.learning.luban.homework.fieldinfo;

import com.sgx.learning.luban.homework.attributes.AttributeHandlerUtils;
import com.sgx.learning.luban.homework.attributes.AttributeInfo;
import com.sgx.learning.luban.homework.basictype.U2;
import com.sgx.learning.luban.homework.constantpool.ConstantPoolInfo;
import lombok.Data;

import java.io.IOException;
import java.io.InputStream;


@Data
public class FieldInfo {
    private short accessFlags;
    private short nameIndex;
    private short descriptorIndex;
    private short attributesCount;
    private AttributeInfo[] attributeInfos;

    public void read(InputStream is, ConstantPoolInfo[] constantPoolInfos) throws IOException {
        this.accessFlags = U2.read(is).getValue();
        this.nameIndex = U2.read(is).getValue();
        this.descriptorIndex = U2.read(is).getValue();
        this.attributesCount = U2.read(is).getValue();
        this.attributeInfos = AttributeHandlerUtils.getAttribute(attributesCount,is,constantPoolInfos);
    }
}
